﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Xml;

namespace XNAGame_Lab1
{
    public class Zoombie : MyXNAButton
    {
        public event EventHandler Attack;
        public event EventHandler Move;
        int _Damp;

        public int Damp
        {
            get { return _Damp; }
            set { _Damp = value; }
        }
        String _Name;

        public String Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        int _HP;//mau

        public int HP
        {
            get { return _HP; }
            set { _HP = value; }
        }
        double _Def;//suc tan cong

        public double Def
        {
            get { return _Def; }
            set { _Def = value; }
        }
        /// <summary>
        /// chien luoc thit hay mat troi
        /// </summary>
        GameStrategy _GameStategy;
        StrategyZoombie _Strategy;

        public StrategyZoombie Strategy
        {
            get { return _Strategy; }
            set { _Strategy = value; }
        }
        public GameStrategy GameStategy
        {
            get { return _GameStategy; }
            set { _GameStategy = value; }
        }
        public Zoombie(ContentManager content, List<string> strTexture, int nSprites, Vector2 topleft, Vector2 size, int cost, GameStrategy stategy, string name,int def,int damp, int hp,       StrategyZoombie StrateMove)
            : base(content, strTexture, nSprites, topleft, size)
        {
            this.Name = name;
            this.Cost = cost;
            this._GameStategy = stategy;
            this.Strategy = StrateMove;
            this._Damp = damp;
            this._Def = def;
            this._HP = hp;
        }

        public Zoombie(ContentManager content, string refix, int nSprites, Vector2 topleft, Vector2 size, int cost, GameStrategy stategy, string name, int def, int damp, int hp, StrategyZoombie StrateMove)
            : base(content, refix, nSprites, topleft, size)
        {
            this.Strategy = StrateMove;

            this.Cost = cost;
            this._GameStategy = stategy;
            this.Name = name;
            this._Damp = damp;
            this._Def = def;
            this._HP = hp;
        }

        public Zoombie(ContentManager content, string strXML)
            : base(content, strXML)
        {

        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //  AnimalMove();
            base.Draw(gameTime, spriteBatch);
        }

        public override void Update(GameTime gameTime)
        {

            if (Attack != null)
            {
                if (flag == 0 && fmove == 0)
                {
                    Attack(this, EventArgs.Empty);
                    flag = 1;
                    fmove = 1;
                }
                
                
            }
            else
            {
                
                    this.TopLeft = Strategy.Move(TopLeft);
                    flag = 0;
            
            }
            if (Move != null)
            {
                if (fmove == 3 && flag == 1)
                {
                    Move(this, EventArgs.Empty);
                    fmove = 2;
                    flag = 0;
                }
                if (fmove == 2)
                {
                   this.TopLeft= Strategy.Move(TopLeft);
                }

            }

                base.Update(gameTime);
        }
        int flag = 0;
        int fmove = 0;
        private ContentManager Content;
        private string p;
        private int p_2;
        private Vector2 vector2;
        private Vector2 vector2_2;
        private ZoombieStone zoombieStone;

        public int Fmove
        {
            get { return fmove; }
            set { fmove = value; }
        }

        public int Flag
        {
            get { return flag; }
            set { flag = value; }
        }
        /// <summary>
        /// ham kiem tra va cham 
        /// </summary>
        public virtual bool isCollide(Vector2 _topleft, Vector2 _Size)
        {
            if (CollisionDetection2D.BoundingRectangle(
                (int)this._TopLeft.X, (int)this._TopLeft.Y, (int)this._Size.X,
               (int)this._Size.Y
               , (int)_topleft.X,
               (int)_topleft.Y,
              (int)_Size.X,
               (int)_Size.Y))
                return true;
            return false;

        }

        /// <summary>
        /// event 
        /// </summary>
        /// <returns></returns>
        public bool isDie()
        {
            if (this.HP == 0)
                return true;
            return false;
        }


    }
}